const reg = {
	bankCard: (p) => {
		return (/^([1-9]{1})(\d{14}|\d{18})$/.test(p))
	},
	id: (p) => {
		return (/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(p))
	},
	regMobile: (p) => {
		return (/^1[3456789]\d{9}$/.test(p))
	},
	regNumber: (p) => {
		return (/^[0-9]*$/.test(p))
	},
	reg2Float: (p) => {
		return (/^[0-9]+(.[0-9]{1,2})?$/.test(p))
	},
	regPhone: (p) => {
		return /^([0-9]{3,4})?(-)?[0-9]{7,8}$/.test(p)
	},
	regEmail: (p) => {
		return /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(p)
	},
	regMoney: (p) => {
		return /^\d+(\.\d{0,2})?$|^\.\d{1,2}$/.test(p)
	},
	regTel (t) {
		return reg.regMobile(t) || reg.regPhone(t)
	},
	regPassword: (p) => {
		return (/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{8,20}$/.test(p))
	},
	regMsgCode: (c) => {
		return (/^\d{6}$/.test(c))
	},
    regServiceCode: (c) => {
        return (/^[0-9a-zA-Z]{1,10}$/.test(c))
    },
	regJobNumber: (c) => {
        return (/^[0-9a-zA-Z]{1,20}$/.test(c))
	},
    regUserName: (c) => {
        return (/^[0-9a-zA-Z]{1,30}$/.test(c))
    },
	regOrganizeCode: (c) => {
        return (/^[0-9a-zA-Z]{3,20}$/.test(c))
	},
	regIdNumber: (id) => {
		return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(id)
	},
	regAppCode: (c) => {
		return (/^[0-9A-Z]{4,16}$/.test(c))
	},
	regDriverPws: (c)=> {
        return (/^[0-9a-zA-Z]{4,8}$/.test(c))
	},
	regDriverName: (c) => {
		return (/^[\u4e00-\u9fa5]{1,20}$/.test(c))
	},
	validateId(rule, value, callback) {
		if( value ) {
			if(reg.id(value)) {
				callback()
			} else {
				callback(new Error('身份证格式错误'))
			}
		} else {
			callback()
		}
	},
	validateDriverName(rule, value, callback) {
        if( value ) {
            if(reg.regDriverName(value)) {
                callback()
            } else {
                callback(new Error('姓名应为1-20位中文'))
            }
        } else {
            callback()
        }
	},bankCardCode(rule, value, callback) {
		if( value ) {
			if(reg.regDriverName(value)) {
				callback()
			} else {
				callback(new Error('请输入银行'))
			}
		} else {
			callback()
		}
	},
	validateDriverPws(rule, value, callback) {
        if( value ) {
            if(reg.regDriverPws(value)) {
                callback()
            } else {
                callback(new Error('密码为4-8位字母和数字组合'))
            }
        } else {
            callback()
        }
	},
	validateJobNumber(rule, value, callback) {
		if( value ) {
			if(reg.regJobNumber(value)) {
				callback()
			} else {
                callback(new Error('工号为1-20位字母和数字组合'))
			}
		} else {
			callback()
		}
	},
	validateServiceCode(rule, value, callback) {
		if( reg.regServiceCode(value) ) {
            callback()
		} else {
            callback(new Error('服务商编号为1-10位字母和数字组合'))
		}
	},
	validateOrganizeCode(rule, value, callback) {
        if (reg.regOrganizeCode(value)) {
            callback()
        } else {
            callback(new Error('机构编码为3-20位字母和数字组合'))
        }
	},
	validateAppCode(rule, value, callback) {
        if (reg.regAppCode(value)) {
            callback()
        } else {
            callback(new Error('appCode为4-16位大写字母和数字'))
        }
	},
	validateTel (rule, value, callback) {
		if( value ) {
            if (reg.regTel(value)) {
                callback()
            } else {
                callback(new Error('电话号码格式不正确'))
            }
		} else {
			callback()
		}
	},
    validateTelNoRequired (rule, value, callback) {
	    if(value) {
            if (reg.regTel(value)) {
                callback()
            } else {
                callback(new Error('电话号码格式不正确'))
            }
        } else {
            callback()
        }

    },
	validateDistanceKm(rule, value, callback) {
		if( reg.reg2Float(value) ) {
			callback();
		} else {
            callback(new Error('公里数格式不正确'))
		}
	},
	validateMobile (rule, value, callback) {
		if (reg.regMobile(value)) {
			callback()
		} else {
			callback(new Error('手机号码格式不正确'))
		}
	},
	validateMobileNoRequire(rule, value, callback) {
		if(value) {
            if (reg.regMobile(value)) {
                callback()
            } else {
                callback(new Error('手机号码格式不正确'))
            }
		} else {
			callback()
		}
	},
	validateMoney(rule, value, callback) {
	    if( value ) {
            if( reg.regMoney(value) ) {
                callback()
            } else {
                callback(new Error('金额格式不正确'))
            }
        } else {
            callback()
        }
	},
	validateDrivingScore(rule, value, callback) {
		if( value ) {
			if( reg.regNumber(value) ) {
				callback()
			} else {
				callback(new Error('驾驶分不正确'))
			}
		} else {
			callback()
		}
	},
	validateBankCard(rule, value, callback) {
		if( value ) {
			if( reg.bankCard(value) ) {
				callback()
			} else {
				callback(new Error('银行卡号不正确'))
			}
		} else {
			callback()
		}
	}
}

export default reg
